﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

#include "GmepCloudData.h"
#include "UniIdentity.h"
#include "GmepCollaborationErrorCodes.h"
#include "IEntity.h"
#include "GmepProjectConfigTypes.h"
#include "GapICoordinate.h"
#include "OwnerPtr.h"
#include "GbmpQuickCast.h"

namespace gcmp
{
    class ElementId;
    class IDocument;
}

namespace gdc
{
    class ICollaborationProject;
    class IAxisGrid;
    enum class ConfigType;
}

namespace gap
{
    class IGridNew;
    enum class CoordinateType;
}

namespace gmep
{
    class GmepICollaborationLevelConfigSet;
    class GmepICollaborationGridConfigSet;
    class GmepICollaborationLevelConfig;
    class GmepICollaborationGridConfig;
    class GmepICollaborationBuildingConfig;
    class GmepICollaborationCoordinateConfig;
    enum class BuildingType;

    ////////////////////////////////////
    // 协同项目配置
    class GMEP_CLOUD_DATA_EXPORT ICollaborationProjectConfigs : public gap::IEntity
    {
        DEFINE_CAST_DERIVED(ICollaborationProjectConfigs, IEntity)
    public:
        // 创建当前本地项目配置，已有配置时返回nullptr
        static ICollaborationProjectConfigs* Create(gcmp::IDocument* pDocument);

        // 获取当前本地项目配置，无配置时返回nullptr
        static const ICollaborationProjectConfigs* Get(const gcmp::IDocument* pDocument);
        static ICollaborationProjectConfigs* GetFW(gcmp::IDocument* pDocument);

    public:
        virtual const gcmp::IElement* GetOwnerElement() const = 0 ;
        virtual gcmp::IElement* GetOwnerElement() = 0;;
        // 加载子项
        virtual bool LoadBuilding(gcmp::IDocument* pDocument, const std::wstring& buildingId) = 0;

        // 加载项目级标高设置
        virtual ProjectItemUpdateResult LoadProjectLevelConfigs(gcmp::IDocument* pDocument, const std::vector<MajorType>& majorFilter
            , std::wstring* pErrorMsg, bool isCopyingWorkUnit) = 0;

        // 加载项目级轴网设置
        virtual ProjectItemUpdateResult LoadCloudGridConfigs(gcmp::OwnerPtr<GmepICollaborationGridConfigSet> gridConfigSet) = 0;

        // 创建项目级轴线
        virtual gap::IGridNew* CreateGrid(gcmp::IDocument* pDoc, gmep::GmepICollaborationGridConfig* pGridConfig) = 0;

        // 删除不需要的轴网标高
        virtual bool DeleteLevelGrid(gcmp::IDocument* pDoc, const gcmp::ElementId& eleId) = 0;

        // 加载项目级坐标设置
        virtual ProjectItemUpdateResult LoadProjectCoordinateConfig(gcmp::IDocument* pDocument,
            const std::wstring& correspondingBuildingName, gcmp::OwnerPtr<GmepICollaborationCoordinateConfig> opCoordConfig,
            gap::CoordinateType coordType, std::wstring* pErrorMsg) = 0;

        // 子项列表版本
        virtual Int32 GetBuildingListVersion() const = 0;
        virtual void SetBuildingListVersion(Int32 val) = 0;

        // 子项
        virtual const GmepICollaborationBuildingConfig* GetBuildingConfig() const = 0;
        virtual GmepICollaborationBuildingConfig* GetBuildingConfigFW() = 0;
        virtual bool SetBuildingConfig(gcmp::OwnerPtr<GmepICollaborationBuildingConfig> config) = 0;
        virtual BuildingType GetBuildingType() const = 0;
        virtual gcmp::ElementId GetBuildingElementId() const = 0;
        virtual std::wstring GetBuildingId() const = 0;
        virtual BuildingUpdateError UpdateBuilding(gcmp::IDocument* pDocument) = 0;
        virtual BuildingUpdateError UpdateBuilding(const GmepICollaborationBuildingConfig* pNewConfig) = 0;

        // 坐标
        virtual const GmepICollaborationCoordinateConfig* GetCoordinateConfig() const = 0;
        virtual GmepICollaborationCoordinateConfig* GetCoordinateConfigFW() = 0;
        virtual bool SetCoordinateConfig(gcmp::OwnerPtr<GmepICollaborationCoordinateConfig> config) = 0;

        // 标高
        virtual const GmepICollaborationLevelConfigSet* GetLevelConfigSet() const = 0;
        virtual GmepICollaborationLevelConfigSet* GetLevelConfigSetFW() = 0;
        virtual bool SetLevelConfigSet(gcmp::OwnerPtr<GmepICollaborationLevelConfigSet> configset) = 0;
        virtual GmepICollaborationLevelConfig* GetLevelConfigFW(const std::wstring& levelId) = 0;
        virtual GmepICollaborationLevelConfig* GetLevelConfigFW(const gcmp::ElementId& levelElementId) = 0;
        virtual const GmepICollaborationLevelConfig* GetLevelConfig(const gcmp::ElementId& levelElementId) const = 0;
        virtual const GmepICollaborationLevelConfig* GetLevelConfig(const std::wstring& levelId) const = 0;

        // 轴网
        virtual const GmepICollaborationGridConfigSet* GetGridConfigSet() const = 0;
        virtual GmepICollaborationGridConfigSet* GetGridConfigSetFW() = 0;
        virtual bool SetGridConfigSet(gcmp::OwnerPtr<GmepICollaborationGridConfigSet> configset) = 0;
        virtual bool GetGridMap(std::map<gcmp::ElementId, std::wstring>& elementIdToCnofigIdMap) const = 0;

        // 本地协同接口
    public:
        // 加载本地协同的项目级轴网设置
        virtual ProjectItemUpdateResult LoadNativeGridConfigs(gcmp::OwnerPtr<GmepICollaborationGridConfigSet> gridConfigSet) = 0;

        // 加载本地协同的项目级坐标设置
        virtual ProjectItemUpdateResult LoadNativeProjectCoordinateConfig(gcmp::IDocument* pDocument,
            const std::wstring& correspondingBuildingName, gcmp::OwnerPtr<GmepICollaborationCoordinateConfig> opCoordConfig,
            gap::CoordinateType coordType, std::wstring& errorMsg = std::wstring()) = 0;

        // 加载本地协同的项目级标高设置
        virtual ProjectItemUpdateResult LoadNativeProjectLevelConfigs(gcmp::OwnerPtr<GmepICollaborationLevelConfigSet> opLevelConfigSet) = 0;

    };
}
